package com.ruyuan.test.mvc.web;

import com.ruyuan.rapid.client.RapidInvoker;
import com.ruyuan.rapid.client.RapidProtocol;
import com.ruyuan.rapid.client.RapidService;
import com.ruyuan.test.mvc.entity.TestEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RapidService(patternPath = "/test*", protocol = RapidProtocol.HTTP, serviceId = "hello")
public class HelloController {

    private volatile int count;

    @RapidInvoker(path = "/testGet")
    @GetMapping("/testGet")
    public String testGet() {
        return "testGet";
    }

    @RapidInvoker(path = "/testPost")
    @PostMapping("/testPost")
    public String testPost() {
        count++;
        if (count >= 1) {
            System.err.println("<------ ruyuan: ------>");
            count = 0;
        }
        return "ruyuan";
    }

    @RapidInvoker(path = "/testParam")
    @RequestMapping("/testParam")
    public String testParam(@RequestParam String name) {
        count++;
        if (count >= 1) {
            System.err.println("<------ testParam收到请求, name:" + name + " ------>");
            count = 0;
        }
        return name;
    }

    @RapidInvoker(path = "/testEntity")
    @RequestMapping("/testEntity")
    public String testEntity(@RequestBody TestEntity testEntity) {
        String result = "testEntity result :" + testEntity.getName() + testEntity.getAge();
        return result;
    }
}
